import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:laos_mall/common/style/extension_util.dart';

class ImageWidget extends StatelessWidget {
  const ImageWidget({super.key, this.url,this.width,this.height,this.fit,this.file});
  final String? url;
  final double? width;
  final double? height;
  final BoxFit? fit;
  final File? file;
  @override
  Widget build(BuildContext context) {
    if(file != null){
      return Image.file(
        file!,
        width: width,
        height: height,
        fit: fit,
      );
    }
    return (url != null && (url!.startsWith('http://') || url!.startsWith('https://')))
        ? CachedNetworkImage(
      imageUrl: url!,
      width: width,
      height: height,
      fit: fit,
      errorWidget: (context, url, error) => Image.asset(
        'img_empty'.toImgPath(),
        width: width,
        height: height,
        fit: fit,
      ),
    )
        : Image.asset(
      'img_empty'.toImgPath(),
      width: width,
      height: height,
      fit: fit,
    );
  }
}
